<?php
/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:
 * @LastEditors: liuhongbin
 * @LastEditTime: xxx
 */

namespace hiduoke\services;

use FormBuilder\Factory\Elm;
use FormBuilder\Form;
use hiduoke\services\formBuilder\traits\DkElement;
use hiduoke\services\formBuilder\traits\DkFile;
use hiduoke\services\formBuilder\traits\DkForm;
use hiduoke\services\formBuilder\traits\DkShow;

class FormBuilder extends Elm
{
    use DkFile;
    use DkElement;
    use DkShow;
    use DkForm;

    public function __construct()
    {

    }

    /**
     * @param $form Form
     */
    public static function getFormData($form, $title = '', $action = '', $method = '')
    {
        return [
            'rules'  => $form->formRule(),//表单规则
            'title'  => $title ?: $form->getTitle(),//表单标题
            'action' => $action ?: $form->getAction(),//路由地址
            'method' => $method ?: $form->getMethod(),//对应前端提交的方法
            'config' => $form->formConfig(),// 配置项
        ];
    }

    public static function getHelp($msg)
    {
        return ['type' => 'p', 'class' => 'd-text-grey d-size-12', 'children' => [$msg]];
    }
}
